//------------------------------------------------------------------------------
// <copyright company="Telligent Systems">
//     Copyright (c) Telligent Systems Corporation.  All rights reserved.
// </copyright> 
//------------------------------------------------------------------------------

using System;
using System.Xml;
using CommunityServer.Components;

namespace CommunityServer.Files.Components
{
	/// <summary>
	/// Summary description for FileGalleryConfiguration.
	/// </summary>
	public class FileGalleryConfiguration : ApplicationKeyApplicationConfiguration
	{


		#region Public Properties

		private FileGalleryAttachmentSettings _fileSettings;

		[ReadFromConfigurationFileOnly]
		public FileGalleryAttachmentSettings AttachmentSettings
		{
			get{ return _fileSettings;}
			set{_fileSettings=value;}
		}

		int _RssCacheWindowInSeconds = 90;
		public int RssCacheWindowInSeconds 
		{
			get 
			{
				return _RssCacheWindowInSeconds;
			}
			set 
			{
				_RssCacheWindowInSeconds = value;
			}
		}

		int _RssDefaultThreadsPerFeed = 15;
		public int RssDefaultThreadsPerFeed 
		{
			get 
			{
				return _RssDefaultThreadsPerFeed;
			}
			set 
			{
				_RssDefaultThreadsPerFeed = value;
			}
		}
		
		private int aggregatePostCount = 25;
		public int AggregatePostCount
		{
			get { return aggregatePostCount;}
			set {aggregatePostCount = value;}
		}

		#region Popular Posts

		int _PopularPostLevelPosts = 15;
		public int PopularPostLevelPosts 
		{
			get 
			{
                
				return _PopularPostLevelPosts;
			}
			set 
			{
				_PopularPostLevelPosts = value;
			}
		}

		int _PopularPostLevelViews = 200;
		public int PopularPostLevelViews 
		{
			get 
			{
                
				return _PopularPostLevelViews;
			}
			set 
			{
				_PopularPostLevelViews = value;
			}
		}
        
		int _PopularPostLevelDays = 3;
		public int PopularPostLevelDays 
		{
			get 
			{
                
				return _PopularPostLevelDays;
			}
			set 
			{
				_PopularPostLevelDays = value;
			}
		}
		#endregion

		#region Duplicate Posts
		bool _EnableDuplicatePosts = false;
		public bool EnableDuplicatePosts 
		{
			get 
			{
            
				return _EnableDuplicatePosts;
			}
			set 
			{
				_EnableDuplicatePosts = value;
			}
		}

		int _DuplicatePostIntervalInMinutes = 15;
		public int DuplicatePostIntervalInMinutes 
		{
			get 
			{
				return _DuplicatePostIntervalInMinutes;
			}
			set 
			{
				_DuplicatePostIntervalInMinutes = value;
			}
		}
		#endregion

		#endregion

		public FileGalleryConfiguration() {}

		#region Public Methods


		#endregion

		#region Public Static Methods

        private static readonly Type thisType = typeof(FileGalleryConfiguration);

        public static FileGalleryConfiguration GetConfig()
        {
            return GetConfig(true);
        }

		public static FileGalleryConfiguration Instance()
		{
			return GetConfig(true);
		}
		
		public static FileGalleryConfiguration GetConfig(bool useCache)
		{
            return Instance(thisType, useCache) as FileGalleryConfiguration;
		}

		#endregion

	    protected override string ConfigSection
	    {
	        get { return "CommunityServer/FileGalleries"; }
	    }

	    protected override void Initialize(XmlNode node)
	    {
            base.Initialize(node);

            if(node != null)
            {
                XmlNode fs = node.SelectSingleNode("AttachmentSettings");
                this.AttachmentSettings =  Serializer.ConvertToObject(fs,typeof(FileGalleryAttachmentSettings)) as FileGalleryAttachmentSettings;

				XmlAttributeCollection attributeCollection = node.Attributes;
				if(attributeCollection["aggregatePostCount"] != null)
				this.aggregatePostCount = Int32.Parse(attributeCollection["aggregatePostCount"].ToString());
			}
	    }

	    public override ApplicationType ApplicationType
	    {
	        get { return ApplicationType.FileGallery; }
	    }
	}
}
